/*
 * @Author: 欧小兵
 * @Date: 2021-11-26 11:27:08
 * @LastEditors: 欧小兵
 * @LastEditTime: 2021-11-27 15:57:28
 * @FilePath: \pc-collaboration\public\csdk.js
 * @Description:
 */
!(function (t, e) {
    'object' == typeof exports && 'undefined' != typeof module
        ? (module.exports = e())
        : 'function' == typeof define && define.amd
        ? define(e)
        : (t.ES6Promise = e());
})(this, function () {
    'use strict';
    function t(t) {
        var e = typeof t;
        return null !== t && ('object' === e || 'function' === e);
    }
    function e(t) {
        return 'function' == typeof t;
    }
    function n(t) {
        W = t;
    }
    function r(t) {
        z = t;
    }
    function o() {
        return function () {
            return process.nextTick(a);
        };
    }
    function i() {
        return 'undefined' != typeof U
            ? function () {
                  U(a);
              }
            : c();
    }
    function s() {
        var t = 0,
            e = new H(a),
            n = document.createTextNode('');
        return (
            e.observe(n, { characterData: !0 }),
            function () {
                n.data = t = ++t % 2;
            }
        );
    }
    function u() {
        var t = new MessageChannel();
        return (
            (t.port1.onmessage = a),
            function () {
                return t.port2.postMessage(0);
            }
        );
    }
    function c() {
        var t = setTimeout;
        return function () {
            return t(a, 1);
        };
    }
    function a() {
        for (var t = 0; t < N; t += 2) {
            var e = Q[t],
                n = Q[t + 1];
            e(n), (Q[t] = void 0), (Q[t + 1] = void 0);
        }
        N = 0;
    }
    function f() {
        try {
            var t = Function('return this')().require('vertx');
            return (U = t.runOnLoop || t.runOnContext), i();
        } catch (e) {
            return c();
        }
    }
    function l(t, e) {
        var n = this,
            r = new this.constructor(p);
        void 0 === r[V] && x(r);
        var o = n._state;
        if (o) {
            var i = arguments[o - 1];
            z(function () {
                return T(o, r, i, n._result);
            });
        } else j(n, r, t, e);
        return r;
    }
    function h(t) {
        var e = this;
        if (t && 'object' == typeof t && t.constructor === e) return t;
        var n = new e(p);
        return w(n, t), n;
    }
    function p() {}
    function v() {
        return new TypeError('You cannot resolve a promise with itself');
    }
    function d() {
        return new TypeError('A promises callback cannot return that same promise.');
    }
    function _(t, e, n, r) {
        try {
            t.call(e, n, r);
        } catch (o) {
            return o;
        }
    }
    function y(t, e, n) {
        z(function (t) {
            var r = !1,
                o = _(
                    n,
                    e,
                    function (n) {
                        r || ((r = !0), e !== n ? w(t, n) : A(t, n));
                    },
                    function (e) {
                        r || ((r = !0), S(t, e));
                    },
                    'Settle: ' + (t._label || ' unknown promise')
                );
            !r && o && ((r = !0), S(t, o));
        }, t);
    }
    function m(t, e) {
        e._state === Z
            ? A(t, e._result)
            : e._state === $
            ? S(t, e._result)
            : j(
                  e,
                  void 0,
                  function (e) {
                      return w(t, e);
                  },
                  function (e) {
                      return S(t, e);
                  }
              );
    }
    function b(t, n, r) {
        n.constructor === t.constructor && r === l && n.constructor.resolve === h
            ? m(t, n)
            : void 0 === r
            ? A(t, n)
            : e(r)
            ? y(t, n, r)
            : A(t, n);
    }
    function w(e, n) {
        if (e === n) S(e, v());
        else if (t(n)) {
            var r = void 0;
            try {
                r = n.then;
            } catch (o) {
                return void S(e, o);
            }
            b(e, n, r);
        } else A(e, n);
    }
    function g(t) {
        t._onerror && t._onerror(t._result), E(t);
    }
    function A(t, e) {
        t._state === X && ((t._result = e), (t._state = Z), 0 !== t._subscribers.length && z(E, t));
    }
    function S(t, e) {
        t._state === X && ((t._state = $), (t._result = e), z(g, t));
    }
    function j(t, e, n, r) {
        var o = t._subscribers,
            i = o.length;
        (t._onerror = null),
            (o[i] = e),
            (o[i + Z] = n),
            (o[i + $] = r),
            0 === i && t._state && z(E, t);
    }
    function E(t) {
        var e = t._subscribers,
            n = t._state;
        if (0 !== e.length) {
            for (var r = void 0, o = void 0, i = t._result, s = 0; s < e.length; s += 3)
                (r = e[s]), (o = e[s + n]), r ? T(n, r, o, i) : o(i);
            t._subscribers.length = 0;
        }
    }
    function T(t, n, r, o) {
        var i = e(r),
            s = void 0,
            u = void 0,
            c = !0;
        if (i) {
            try {
                s = r(o);
            } catch (a) {
                (c = !1), (u = a);
            }
            if (n === s) return void S(n, d());
        } else s = o;
        n._state !== X ||
            (i && c ? w(n, s) : c === !1 ? S(n, u) : t === Z ? A(n, s) : t === $ && S(n, s));
    }
    function M(t, e) {
        try {
            e(
                function (e) {
                    w(t, e);
                },
                function (e) {
                    S(t, e);
                }
            );
        } catch (n) {
            S(t, n);
        }
    }
    function P() {
        return tt++;
    }
    function x(t) {
        (t[V] = tt++), (t._state = void 0), (t._result = void 0), (t._subscribers = []);
    }
    function C() {
        return new Error('Array Methods must be provided an Array');
    }
    function O(t) {
        return new et(this, t).promise;
    }
    function k(t) {
        var e = this;
        return new e(
            L(t)
                ? function (n, r) {
                      for (var o = t.length, i = 0; i < o; i++) e.resolve(t[i]).then(n, r);
                  }
                : function (t, e) {
                      return e(new TypeError('You must pass an array to race.'));
                  }
        );
    }
    function F(t) {
        var e = this,
            n = new e(p);
        return S(n, t), n;
    }
    function Y() {
        throw new TypeError(
            'You must pass a resolver function as the first argument to the promise constructor'
        );
    }
    function q() {
        throw new TypeError(
            "Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function."
        );
    }
    function D() {
        var t = void 0;
        if ('undefined' != typeof global) t = global;
        else if ('undefined' != typeof self) t = self;
        else
            try {
                t = Function('return this')();
            } catch (e) {
                throw new Error(
                    'polyfill failed because global object is unavailable in this environment'
                );
            }
        var n = t.Promise;
        if (n) {
            var r = null;
            try {
                r = Object.prototype.toString.call(n.resolve());
            } catch (e) {}
            if ('[object Promise]' === r && !n.cast) return;
        }
        t.Promise = nt;
    }
    var K = void 0;
    K = Array.isArray
        ? Array.isArray
        : function (t) {
              return '[object Array]' === Object.prototype.toString.call(t);
          };
    var L = K,
        N = 0,
        U = void 0,
        W = void 0,
        z = function (t, e) {
            (Q[N] = t), (Q[N + 1] = e), (N += 2), 2 === N && (W ? W(a) : R());
        },
        B = 'undefined' != typeof window ? window : void 0,
        G = B || {},
        H = G.MutationObserver || G.WebKitMutationObserver,
        I =
            'undefined' == typeof self &&
            'undefined' != typeof process &&
            '[object process]' === {}.toString.call(process),
        J =
            'undefined' != typeof Uint8ClampedArray &&
            'undefined' != typeof importScripts &&
            'undefined' != typeof MessageChannel,
        Q = new Array(1e3),
        R = void 0;
    R = I ? o() : H ? s() : J ? u() : void 0 === B && 'function' == typeof require ? f() : c();
    var V = Math.random().toString(36).substring(2),
        X = void 0,
        Z = 1,
        $ = 2,
        tt = 0,
        et = (function () {
            function t(t, e) {
                (this._instanceConstructor = t),
                    (this.promise = new t(p)),
                    this.promise[V] || x(this.promise),
                    L(e)
                        ? ((this.length = e.length),
                          (this._remaining = e.length),
                          (this._result = new Array(this.length)),
                          0 === this.length
                              ? A(this.promise, this._result)
                              : ((this.length = this.length || 0),
                                this._enumerate(e),
                                0 === this._remaining && A(this.promise, this._result)))
                        : S(this.promise, C());
            }
            return (
                (t.prototype._enumerate = function (t) {
                    for (var e = 0; this._state === X && e < t.length; e++)
                        this._eachEntry(t[e], e);
                }),
                (t.prototype._eachEntry = function (t, e) {
                    var n = this._instanceConstructor,
                        r = n.resolve;
                    if (r === h) {
                        var o = void 0,
                            i = void 0,
                            s = !1;
                        try {
                            o = t.then;
                        } catch (u) {
                            (s = !0), (i = u);
                        }
                        if (o === l && t._state !== X) this._settledAt(t._state, e, t._result);
                        else if ('function' != typeof o) this._remaining--, (this._result[e] = t);
                        else if (n === nt) {
                            var c = new n(p);
                            s ? S(c, i) : b(c, t, o), this._willSettleAt(c, e);
                        } else
                            this._willSettleAt(
                                new n(function (e) {
                                    return e(t);
                                }),
                                e
                            );
                    } else this._willSettleAt(r(t), e);
                }),
                (t.prototype._settledAt = function (t, e, n) {
                    var r = this.promise;
                    r._state === X &&
                        (this._remaining--, t === $ ? S(r, n) : (this._result[e] = n)),
                        0 === this._remaining && A(r, this._result);
                }),
                (t.prototype._willSettleAt = function (t, e) {
                    var n = this;
                    j(
                        t,
                        void 0,
                        function (t) {
                            return n._settledAt(Z, e, t);
                        },
                        function (t) {
                            return n._settledAt($, e, t);
                        }
                    );
                }),
                t
            );
        })(),
        nt = (function () {
            function t(e) {
                (this[V] = P()),
                    (this._result = this._state = void 0),
                    (this._subscribers = []),
                    p !== e &&
                        ('function' != typeof e && Y(), this instanceof t ? M(this, e) : q());
            }
            return (
                (t.prototype['catch'] = function (t) {
                    return this.then(null, t);
                }),
                (t.prototype['finally'] = function (t) {
                    var n = this,
                        r = n.constructor;
                    return e(t)
                        ? n.then(
                              function (e) {
                                  return r.resolve(t()).then(function () {
                                      return e;
                                  });
                              },
                              function (e) {
                                  return r.resolve(t()).then(function () {
                                      throw e;
                                  });
                              }
                          )
                        : n.then(t, t);
                }),
                t
            );
        })();
    return (
        (nt.prototype.then = l),
        (nt.all = O),
        (nt.race = k),
        (nt.resolve = h),
        (nt.reject = F),
        (nt._setScheduler = n),
        (nt._setAsap = r),
        (nt._asap = z),
        (nt.polyfill = D),
        (nt.Promise = nt),
        nt.polyfill(),
        nt
    );
});

/**
 * Created by yangchao on 2019-3-28.
 * v2.0
 * last update: 2019-6-3
 */

/**
 *
 浜嬩欢涓庨挬瀛愰兘鍏佽娉ㄥ唽澶氭銆傚畠浠殑鍖哄埆鍦ㄤ簬锛屾瘡涓簨浠跺洖璋冪浉浜掔嫭绔嬶紝浜嬩欢鍙傛暟褰兼涓嶅奖鍝嶏紝
 鑰岄挬瀛愬湪澶勭悊鍑芥暟涓細鏈夋搷浣滀慨鏀逛笂涓嬫枃鏁版嵁context鐨勫満鏅紝鍚屼竴涓挬瀛愯娉ㄥ唽澶氭鏃讹紝浼氬叡浜竴浠戒笂涓嬫枃鏁版嵁
 */

(function (scope) {
    'use strict';

    if (scope.csdk) return;

    var noop = function () {};
    var isObject = function (obj) {
        return Object.prototype.toString.call(obj) === '[object Object]';
    };
    var mergeObject_ = function (dest, source) {
        Object.keys(source).forEach(function (name) {
            var oldValue = dest[name];
            var newValue = source[name];
            if (isObject(oldValue) && isObject(newValue)) {
                dest[name] = mergeObject_(oldValue, newValue);
            } else {
                dest[name] = newValue;
            }
        });
        return dest;
    };
    var mergeObject = function (dest) {
        var sources = Array.prototype.slice.call(arguments, 1);
        sources.forEach(function (source) {
            mergeObject_(dest, source);
        });
        return dest;
    };
    var deepClone = function (obj) {
        return JSON.parse(JSON.stringify(obj));
    };

    //鍏煎IE8 鎵╁睍indexOf鏂规硶
    if (!Array.prototype.indexOf) {
        Array.prototype.indexOf = function (elt /*, from*/) {
            var len = this.length >>> 0;
            var from = Number(arguments[1]) || 0;
            from = from < 0 ? Math.ceil(from) : Math.floor(from);
            if (from < 0) from += len;
            for (; from < len; from++) {
                if (from in this && this[from] === elt) return from;
            }
            return -1;
        };
    }

    var _eventPool = {};
    var _hookPool = {};
    var _middlewares = {};
    var csdk = {
        _: {
            runHook: function (hookName, context) {
                var that = this;
                var handlers = _hookPool[hookName];
                if (handlers instanceof Array) {
                    var len = handlers.length;
                    for (var i = 0; i < len; i++) {
                        //姣忎竴涓挬瀛愶紝閮藉叡浜竴浠戒笂涓嬫枃鏁版嵁context
                        try {
                            handlers[i].call(that, context);
                        } catch (ex) {
                            console.log(ex);
                        }
                    }
                }
            },
            emitEvent: function (eventName, params) {
                var handlers = _eventPool[eventName];
                if (handlers instanceof Array) {
                    var len = handlers.length;
                    for (var i = 0; i < len; i++) {
                        //绠€鍗曠殑淇濊瘉浜嬩欢涔嬮棿鍙傛暟涓嶇浉浜掑奖鍝�
                        try {
                            //var e = JSON.parse(JSON.stringify(params));
                            //TODO 鏆傛椂鐩存帴浼犲叆params锛屽悗缁啓涓€涓猚lone鏂规硶锛岄伩鍏嶅弬鏁板共鎵�
                            handlers[i].call(null, params);
                        } catch (ex) {}
                    }
                }
            },
            runMiddleware: function (name, params) {
                var handlers = _middlewares[name];
                var promise = Promise.resolve(params);
                handlers = handlers ? handlers.slice(0) : [];
                while (handlers.length) {
                    var middleware = handlers.shift();
                    promise = promise.then(middleware.resolved, middleware.rejected);
                }
                return promise;
            },
        },
        event: {
            /**
             * 鐢ㄤ簬瀹㈠紑浠ｇ爜涓敞鍐岃〃鍗曠敓鍛藉懆鏈熶簨浠�
             * @param eventName
             * @param handler
             */
            on: function (eventName, handler) {
                if (typeof handler === 'function') {
                    if (_eventPool[eventName] instanceof Array) {
                        _eventPool[eventName].push(handler);
                    } else {
                        _eventPool[eventName] = [handler];
                    }
                } else {
                    throw new Error('handler is not a function on csdk.event.on');
                }
                return function () {
                    csdk.event.off(eventName, handler);
                };
            },
            off: function (eventName, handler) {
                var handlers = _eventPool[eventName];
                if (handlers instanceof Array) {
                    if (handler) {
                        var index = handlers.indexOf(handler);
                        if (index !== -1) {
                            handlers.splice(index, 1);
                        }
                    } else {
                        handlers.splice(0);
                    }
                }
            },
        },
        hook: function (hookName, handler) {
            if (typeof handler === 'function') {
                if (_hookPool[hookName] instanceof Array) {
                    _hookPool[hookName].push(handler);
                } else {
                    _hookPool[hookName] = [handler];
                }
            } else {
                throw new Error('handler is not a function on csdk.hook');
            }
        },
        middleware: function (name, opt) {
            if (!_middlewares[name]) _middlewares[name] = [];
            var handlers = _middlewares[name];
            var priority = typeof opt.priority === 'number' ? opt.priority : 20;
            priority = Math.min(priority, 10000);
            priority = Math.max(priority, -10000);
            var middleware = {
                priority: priority,
                resolved: opt.success,
                rejected: opt.error,
            };
            var appended = false;
            for (var i = 0, l = handlers.length; i < l; ++i) {
                var current = handlers[i];
                if (current.priority < middleware.priority) {
                    handlers.splice(i, 0, middleware);
                    appended = true;
                    break;
                }
            }
            if (!appended) {
                handlers.push(middleware);
            }
            return function () {
                for (var i = 0, l = handlers.length; i < l; ++i) {
                    if (handlers[i] === middleware) {
                        return handlers.splice(i, 1);
                    }
                }
            };
        },
        ctrl: {
            /**
             * 鐢ㄤ簬瀹㈠紑娉ㄥ唽鏇挎崲鏍囧噯鎺т欢鐨勬帴鍙ｏ紝濡傛灉娉ㄥ唽浜嗘煇涓帶浠剁殑瀹炵幇锛岃〃鍗曞湪娓叉煋鏃朵笉浣跨敤瀹樻柟鎺т欢锛岀洿鎺ヤ娇鐢ㄥ寮€瀹炵幇
             * @param ctrlType
             * @param handler
             */
            register: function (ctrlType, handler) {
                throw new Error('csdk.ctrl.register is not implemented');
            },
            /**
             * 鏍规嵁鎺т欢绫诲瀷鑾峰彇鍏蜂綋瀹炵幇鐨勬帴鍙�
             * @param ctrlType
             */
            getInstance: function (ctrlType) {
                throw new Error('csdk.ctrl.getInstance is not implemented');
            },
            destroy: function (ctrlType) {
                throw new Error('csdk.ctrl.destroy is not implemented');
            },
        },
        component: (function () {
            function XComponent(opt) {
                var ctx = this;
                var option = opt.option;
                var proto = opt.proto;
                this._isDestroyed = false;
                this._isBeingDestroyed = false;
                // mix data
                for (var i in option) {
                    this['$' + i] = option[i];
                }
                this.$option = option;
                this.$events = [];
                this.$data = csdk.core.getFieldData({
                    ref: this.$ref,
                    clientId: this.$clientId,
                    fieldId: this.$fieldId,
                    recordId: this.$recordId || '',
                    tableName: this.$recordId ? this.$tableName : '',
                });
                // mix method
                for (var i in proto) {
                    this[i] = proto[i];
                }
                // watch data
                this.$fieldWatcher = this.$on(this.$uuid, function () {
                    if (ctx._isDestroyed || ctx._isBeingDestroyed) return;
                    ctx.$update();
                });
            }
            XComponent.prototype = {
                constructor: XComponent,
                $init: function (param) {
                    var ctx = this;
                    var returned = this.init(this.$option, this.$container);
                    if (returned && returned.then) {
                        // 寮傛娓叉煋
                        returned.then(
                            function () {
                                ctx.$emit(context.EVENT_RENDERED);
                            },
                            function (err) {
                                ctx.$emit(context.EVENT_RENDERED, { error: err });
                            }
                        );
                    } else {
                        // 鍚屾娓叉煋
                        Promise.resolve().then(function () {
                            ctx.$emit(context.EVENT_RENDERED);
                        });
                    }
                },
                $update: function () {
                    this.$data = csdk.core.getFieldData({
                        ref: this.$ref,
                        clientId: this.$clientId,
                        fieldId: this.$fieldId,
                        recordId: this.$recordId || '',
                        tableName: this.$recordId ? this.$tableName : '',
                    });
                    var ctx = this;
                    var returned = this.update();
                    if (returned && returned.then) {
                        returned.then(
                            function () {
                                ctx.$emit(context.EVENT_UPDATED);
                            },
                            function (err) {
                                ctx.$emit(context.EVENT_UPDATED, { error: err });
                            }
                        );
                    } else {
                        Promise.resolve().then(function () {
                            ctx.$emit(context.EVENT_UPDATED);
                        });
                    }
                },
                $destroy: function () {
                    if (this._isDestroyed || this._isBeingDestroyed) return;
                    this._isBeingDestroyed = true;
                    this.$events.splice(0).forEach(function (unbind) {
                        unbind();
                    });
                    var ctx = this;
                    var returned = this.destroy();
                    if (returned && returned.then) {
                        returned.then(
                            function () {
                                ctx._isDestroyed = true;
                                ctx._isBeingDestroyed = false;
                                ctx.$emit(context.EVENT_DESTROYED);
                            },
                            function (err) {
                                ctx._isDestroyed = true;
                                ctx._isBeingDestroyed = false;
                                ctx.$emit(context.EVENT_DESTROYED, { error: err });
                            }
                        );
                    } else {
                        this._isDestroyed = true;
                        this._isBeingDestroyed = false;
                        ctx.$emit(context.EVENT_DESTROYED);
                    }
                },
                $t: function (str, replacer) {
                    return csdk.core.isPC() ? top.$.i18n(str, replacer) : cmp.i18n(str, replacer);
                },
                $set: function (data) {
                    csdk.core.setFieldData({
                        ref: this.$ref,
                        clientId: this.$clientId,
                        fieldId: this.$fieldId,
                        recordId: this.$recordId,
                        tableName: this.$tableName,
                        fieldData: data,
                    });
                    this.$data = csdk.core.getFieldData({
                        ref: this.$ref,
                        clientId: this.$clientId,
                        fieldId: this.$fieldId,
                        recordId: this.$recordId || '',
                        tableName: this.$recordId ? this.$tableName : '',
                    });
                },
                $on: function (el, type, fn) {
                    var ctx = this;
                    var isDomEvt = true;
                    var rawUnbind;
                    if (typeof el === 'string') {
                        fn = type;
                        type = el;
                        isDomEvt = false;
                    }
                    var events = this.$events;
                    var listener = isDomEvt
                        ? function (evt) {
                              return fn && fn(evt);
                          }
                        : function (evt) {
                              if (type === ctx.$uuid || evt.type === ctx.$uuid) {
                                  return fn && fn(evt);
                              }
                          };
                    var unbind = function () {
                        if (isDomEvt) {
                            el.removeEventListener(type, listener, false);
                        } else {
                            rawUnbind();
                        }
                        for (var i = 0, l = events.length; i < l; ++i) {
                            if (events[i] === listener) {
                                events.splice(i, 1);
                                break;
                            }
                        }
                    };
                    if (isDomEvt) {
                        el.addEventListener(type, listener, false);
                    } else {
                        rawUnbind = csdk.event.on(type, listener);
                    }
                    events.push(unbind);
                    return unbind;
                },
                $emit: function (el, type, evt) {
                    if (typeof el === 'string') {
                        evt = type;
                        type = el;
                        evt = evt || {};
                        evt.type = this.$uuid;
                        return csdk._.emitEvent(type, evt);
                    } else {
                        // 寰呮敮鎸乨om浜嬩欢
                    }
                },
                init: function () {},
                update: function () {},
                destroy: function () {},
                beforeSave: function () {},
                afterSave: function () {},
            };

            var __cached__ = {};
            var __instanced__ = {};
            var getDef = function (name) {
                return __cached__[name] && __cached__[name].registry;
            };
            var getInstalledDef = function (name) {
                var def = __cached__[name];
                if (def && def.installed.state === 'success') {
                    return def.registry;
                }
                return null;
            };
            var flushCommonErr = function (err) {
                console.error(err);
            };
            var context = {
                __cached__: __cached__,
                __instanced__: __instanced__,
                EVENT_RENDERED: 'com.seeyon.form.field.rendered',
                EVENT_UPDATED: 'com.seeyon.form.field.updated',
                EVENT_DESTROYED: 'com.seeyon.form.field.destroyed',
                Super: XComponent,
                has: function (name) {
                    return !!getDef(name);
                },
                get: function (name) {
                    return getInstalledDef(name);
                },
                register: function (isInternal, name, factory) {
                    var cached = __cached__;
                    var rspace = /\s+/;
                    var registry;
                    // 娉ㄥ唽鑷畾涔夋帶浠�
                    // @param name          鑷畾涔夋帶浠剁殑inputType
                    // @param factory       鑷畾涔夋帶浠跺疄鐜�
                    // 娉ㄥ唽鏍囧噯鎺т欢
                    // @param isInternal    涓簍rue鍗充唬琛ㄦ敞鍐屾爣鍑嗘帶浠�
                    // @param name          鎺т欢鐨勬暟鎹煙id
                    // @param factory       鏍囧噯鎺т欢瀹炵幇
                    if (typeof isInternal === 'string') {
                        factory = name;
                        name = isInternal;
                        isInternal = false;
                    }
                    isInternal = !!isInternal;
                    name = name.replace(/^\s+|\s+$/);
                    if (rspace.test(name)) {
                        name = name.split(rspace);
                    }
                    if (name instanceof Array) {
                        for (var i = 0, l = name.length; i < l; ++i) {
                            this.register(isInternal, name[i], factory);
                        }
                        return;
                    }
                    // 1. 鏍￠獙閫氱敤鍙傛暟
                    if (cached[name]) {
                        // 瑕嗙洊绛栫暐寰呭畾
                        console.warn(
                            name + ' already registered. Last registered will be replaced.'
                        );
                    }
                    try {
                        registry = factory();
                    } catch (ex) {
                        return flushCommonErr(ex);
                    }
                    if (!registry) {
                        return flushCommonErr(name + ' implemented nothing.');
                    }
                    if (!registry.type) {
                        registry.type = 'raw';
                    }
                    // 2. 鎺т欢閫氱敤鎺ュ彛
                    registry.plugin = mergeObject(
                        {
                            install: noop,
                            uninstall: noop,
                            requiredAssert: function (data) {
                                return !!data.value;
                            },
                            fieldLengthAssert: function (data) {
                                return true;
                            },
                            validAssert: function (data) {
                                return true;
                            },
                        },
                        registry.plugin || {}
                    );
                    if (!registry.implement) {
                        return flushCommonErr(name + ' does not implement.');
                    }
                    // registry = {
                    //   type: 'raw|vue',
                    //   plugin: {
                    //     install: function () { },
                    //     uninstall: function () { },
                    //     requireAssert: function () { return true; },
                    //     fieldLengthAssert: function () { return true; },
                    //     validAssert: function () { return true; }
                    //   },
                    //   implement: {
                    //     init: function () { },
                    //     update: function () { },
                    //     destroy: function () { }
                    //   }
                    // }
                    var installed = {
                        state: '0',
                        path: '',
                        result: {},
                        error: null,
                        readyQ: [],
                    };
                    cached[name] = {
                        tuple: name,
                        isInternal: isInternal,
                        registry: registry,
                        installed: installed,
                    };
                    // 3. 鏍囧噯鎺т欢鐩存帴鑷姩瀹夎
                    // TODO: 鏀归€犺嚜瀹氫箟鎺т欢鑷姩鍔犺浇
                    if (isInternal) {
                        this.install(name);
                    }
                },
                install: function (name, opt) {
                    var cached = __cached__;
                    if (!cached[name]) {
                        return console.error(name + ' not found');
                    }
                    var installed = cached[name].installed;
                    var registry = cached[name].registry;
                    var installCtx = deepClone(opt || {});
                    var flushInstallErr = function (err) {
                        err = err || 'uncaught';
                        installed.state = 'fail';
                        installed.error = err;
                        console.error(
                            name +
                                ' meet an installing exception, this may result component render failed. see:\n',
                            err
                        );
                    };
                    var flushInstallReady = function () {
                        installed.state = 'success';
                        installed.readyQ.splice(0).forEach(function (q) {
                            var opt = q instanceof Array ? q[0] : q;
                            var cb = q instanceof Array ? q[1] : noop;
                            context.instantiate(opt).then(cb);
                        });
                    };
                    if (installed.state === 'installing') {
                        // install鏄紓姝ョ殑
                        return;
                    }
                    if (installed.state !== '0') {
                        // install瀹屾垚
                        return;
                    }
                    // 1.鎵ц瀹夎鑴氭湰
                    // 2.瀹夎鎴愬姛鍚庯紝濡傛灉鏈夊疄渚嬪寲闃熷垪锛屽垯绔嬪嵆瀹炰緥鍖�
                    // 3.uninstall鏃舵満涓嶆槑纭紝鏆傛湭瀹炵幇
                    installed.state = 'installing';
                    try {
                        var returned = registry.plugin.install(installCtx);
                        if (returned && returned.then) {
                            var p = returned.then(flushInstallReady, flushInstallErr);
                            p['catch'](flushInstallErr);
                        } else {
                            if (typeof returned === 'undefined') {
                                flushInstallReady();
                            } else {
                                flushInstallErr(returned);
                            }
                        }
                    } catch (ex) {
                        flushInstallErr(ex);
                    }
                },
                instantiate: function (opt) {
                    var cached = __cached__;
                    var instanced = __instanced__;
                    var widgetName = opt.component;
                    var rejectWith = function (reject, err) {
                        console.error(err);
                        reject(err[0]);
                    };
                    if (!cached[widgetName]) {
                        return new Promise(function (resolve, reject) {
                            rejectWith(reject, [widgetName + ' not registered']);
                        });
                    }
                    var registry = cached[widgetName].registry;
                    var installed = cached[widgetName].installed;
                    if (installed.state === '0' || installed.state === 'installing') {
                        return new Promise(function (resolve) {
                            installed.readyQ.push([opt, resolve]);
                        });
                    }
                    if (installed.state !== 'success') {
                        return new Promise(function (resolve, reject) {
                            rejectWith(reject, [
                                name +
                                    ' meet an installing exception, this may result component render failed. see:\n',
                                installed.error,
                            ]);
                        });
                    }
                    var instance = new XComponent({
                        option: opt,
                        proto: registry.implement,
                    });
                    instanced[opt.uuid] = { type: name, item: instance };
                    var promise = Promise.resolve(instance);
                    promise.then(function () {
                        instance.$init();
                    });
                    return promise;
                },
                destroy: function (id) {
                    var instanced = __instanced__;
                    var instance = instanced[id] && instanced[id].item;
                    if (instance) {
                        instance.$destroy();
                        instance = null;
                        delete instanced[id];
                    }
                },
                on: function (type, fn) {
                    return csdk.event.on(type, fn);
                },
                requiredAssert: function (widgetName, data) {
                    var widget = getDef(widgetName);
                    return widget && widget.plugin.requiredAssert(data);
                },
                fieldLengthAssert: function (widgetName, data, length) {
                    var widget = getDef(widgetName);
                    return widget && widget.plugin.fieldLengthAssert(data, length);
                },
                validAssert: function (widgetName, data) {
                    var widget = getDef(widgetName);
                    return widget && widget.plugin.validAssert(data);
                },
            };

            return context;
        })(),
        core: {
            /***
             * 鏍规嵁瀛楁id杩斿洖瀵瑰簲瀛楁鐨勬暟鎹�,濡傛灉鏄富琛ㄥ瓧娈碉紝鍙紶fieldId
             * @param fieldId 濡俧ield0001
             * @param tableName 鏄庣粏琛ㄥ悕绉帮紝鍙湪璇锋眰鏄庣粏琛ㄥ瓧娈典俊鎭椂浼犲叆
             * @param recordId 鏄庣粏琛ㄨid锛屽彧鍦ㄨ姹傛槑缁嗚〃瀛楁淇℃伅鏃朵紶鍏�
             */
            getFieldData: function (fieldId, tableName, recordId) {
                throw new Error('csdk.core.getFieldData is not implemented');
            },
            /**
             * 杩斿洖琛ㄥ崟鎵€鏈夊瓧娈电殑鏁版嵁锛堝墠绔墍鏈夎兘鍙栧埌鐨勫瓧娈碉紝鍚庡彴鏈繑鍥炲埌鍓嶇鐨勫瓧娈垫槸鍙栦笉鍒扮殑锛�
             */
            getFormData: function () {
                throw new Error('csdk.core.getFormData is not implemented');
            },
            /**
             * 鑾峰彇琛ㄥ崟summaryId锛宎ffairId锛宼emplateId锛宮oduleId浠ュ強瑙嗗浘鏉冮檺绛変俊鎭�
             */
            getMetaData: function () {
                throw new Error('csdk.core.getMetaData is not implemented');
            },
            /**
             *鑾峰彇闇€瑕佹彁浜ゅ埌鍚庡彴鐨勮〃鍗曟暟鎹�
             */
            getSubmitData: function () {
                throw new Error('csdk.core.getSubmitData is not implemented');
            },
            /**
       * 鏍规嵁鏌愪釜瀛楁鐨勬弿杩拌缃瀛楁鐨勫€�
       * @supported
       CAP3_PC: none;
       CAP3_M3: none;
       CAP3_寰崗鍚�: none;
       CAP4_PC锛歷7.1+
       CAP4_M3: v7.1+
       CAP4_寰崗鍚�: v7.1+
       * @
       * @param options
       */
            setFieldData: function (options) {
                throw new Error('csdk.core.setFieldData is not implemented');
            },
            /**
             * 閫氳繃data鏇存柊琛ㄥ崟瑙嗗浘鏁版嵁锛宒ata涓哄悗鍙拌繑鍥炵殑缁撴瀯
             * @param data
             */
            patchData: function (data) {
                throw new Error('csdk.core.patchData is not implemented');
            },
            /**
             * 棰勬彁浜ょ殑鎺ュ彛
             */
            preSave: function () {
                throw new Error('csdk.core.preSave is not implemented');
            },
            /**
             * 鑾峰彇鐩爣鏄庣粏琛ㄥ綋鍓嶉€変腑琛岃褰�,杩斿洖record瀵硅薄鎴杗ull
             * @param tableName
             */
            getSelectedRecord: function (tableName) {
                throw new Error('csdk.core.getSelectedRecord is not implemented');
            },
            /**
             * 鍒犻櫎鐩爣鏄庣粏琛ㄧ殑鎸囧畾琛岃褰�
             */
            deleteRecords: function (opts, callback) {
                throw new Error('csdk.core.deleteRecords is not implemented');
            },
            deleteRecord: function (opts, callback) {
                throw new Error('csdk.core.deleteRecord is not implemented');
            },
            /**
             * 澧炲姞鏄庣粏琛�
             */
            addRecord: function (opts, callback) {
                throw new Error('csdk.core.addRecord is not implemented');
            },
            /**
             * 鎷疯礉鏄庣粏琛�
             */
            copyRecord: function (opts, callback) {
                throw new Error('csdk.core.copyRecord is not implemented');
            },
            isPC: function () {
                //鍒ゆ柇鏄惁鏈塩mp
                return window.cmp ? false : true;
            },
            isM3: function () {
                return window.cmp && window.cmp.platform && window.cmp.platform.CMPShell
                    ? true
                    : false;
            },
            /**
             * 鏄惁杞昏〃鍗曪紝榛樿杩斿洖false锛屽湪杞昏〃鍗曚腑瀹炵幇閫昏緫锛岃繑鍥瀟rue
             * @returns {boolean}
             */
            isLightForm: function () {
                return false;
            },
        },
        i18n: {
            /**
             * 鏍规嵁key杩斿洖褰撳墠璇█鐜瀵瑰簲鐨勫浗闄呭寲鏂囨湰
             * @param key
             */
            prop: function (key) {
                throw new Error('csdk.i18n.prop is not implemented');
            },
            /**
             * 鑾峰彇褰撳墠娴忚鍣ㄨ瑷€鐜
             */
            lang: function () {
                throw new Error('csdk.i18n.lang is not implemented');
            },
        },
        util: {
            /**
             * 鎵撳紑閬僵
             */
            openMask: function () {
                throw new Error('csdk.util.openMask is not implemented');
            },
            /**
             * 鍏抽棴閬僵
             */
            closeMask: function () {
                throw new Error('csdk.util.closeMask is not implemented');
            },
            /**
             * 涓婁紶鏂囦欢鐨勬帴鍙�
             * @param callback
             */
            uploadFile: function (callback) {
                throw new Error('csdk.util.uploadFile is not implemented');
            },
            /**
             * 娑堟伅寮规鐨勬帴鍙�
             * @param msg
             */
            alert: function (msg) {
                throw new Error('csdk.util.alert is not implemented');
            },
            /**
             * confirm寮圭獥
             * @param msg
             */
            confirm: function (msg) {
                throw new Error('csdk.util.confirm is not implemented');
            },
            /**
             * 寮傛鍔犺浇璧勬簮鏂囦欢
             */
            loadFile: function () {
                throw new Error('csdk.util.loadFile is not implemented');
            },
            /**
             * ajax鎺ュ彛
             * @param options
             * @param callback
             */
            ajax: function (options, callback) {
                throw new Error('csdk.util.ajax is not implemented');
            },
        },
    };

    csdk.version = '2.0';
    scope.csdk = csdk;
})(this);
(function () {
    if (window.csdk) {
        window.csdk._.emitEvent('pluginChecked', '0');
    }
})();
